import tkinter as tk
import pyautogui
import time
import threading

# 定义停止标志
stop_flag = False


def move_mouse():
    while True:
        try:
            current_x, current_y = pyautogui.position()
            pyautogui.moveTo(current_x + 2, current_y)
            pyautogui.moveTo(current_x, current_y)
            time.sleep(60)
            # print("鼠标移动成功")
        except:
            pass


def start_prevent():
    # print("程序启动成功")
    # t = threading.Thread(target=move_mouse)
    # t.start()
    # root.iconify()
    global stop_flag
    stop_flag = False
    t = threading.Thread(target=move_mouse)
    t.start()
    root.iconify()


root = tk.Tk()
root.title("防止电脑息屏小工具")
# 扩大界面框面积两倍，这里假设原尺寸为 200x100，扩大后为 400x200
root.geometry("400x200")

start_button = tk.Button(root, text="启动防止息屏", command=start_prevent)
start_button.pack(pady=80)
# print("请勿关闭窗口，否则无法启动程序")

root.mainloop()
